﻿function xloader() {
    var xv = [".6.0", ".5.0", ".4.0", ".3.0", ".2.6", ""];
    if (window.XMLHttpRequest) {
        this.loader = new XMLHttpRequest();
    } else {
        for (var i = 0; i < xv.length; i++) {
            try {
                this.loader = new ActiveXObject("msxml2.xmlHttp" + xv[i]);
                break;
            } catch (ex) { }
        }
        if (!this.loader) {
            try {
                this.loader = new ActiveXObject("Microsoft.xmlHttp");
            } catch (ex) { throw ex; }
        }
    }
}
xloader.prototype.get = function(url, data, as, call) {
    url += url.indexOf("?") == -1 ? "?" : "&";
    this.open("get", url + data, as, call);
    this.send(null);
}
xloader.prototype.load = function(url, data, as, call) {
    this.open("post", url, as, call);
    this.setRequestHeader("Content-Length", data.length);
    this.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    this.send(data);
}
//|get|post|head|options|put|delete|trace|
xloader.prototype.open = function(mtd, url, as, call, user, pwd) {
    mtd = mtd || "get";
    url = url || "?";
    if (typeof call != "function") {
        arguments[2] = true;
        arguments[3] = null;
        pwd = arguments[5] = user;
        user = arguments[4] = call;
        if (typeof as == "function") {
            arguments[3] = as;
        } else {
            if (typeof as == "string") {
                user = arguments[4] = as;
                pwd = arguments[5] = call;
            } else {
                arguments[2] = as;
            }
        }
        as = arguments[2];
    }
    this.loader.open(mtd, url, as, user, pwd);
    this.loader.onreadystatechange = this.callreaday;
    this.callreaday.args = arguments;
    this.callreaday.args.that = this;
}
xloader.prototype.setRequestHeader = function(header, value) {
    return this.loader.setRequestHeader(header, value);
}
xloader.prototype.send = function(data) {
    if (data) { this.callreaday.args[1] = data; }
    this.loader.send(this.callreaday.args[1]);
}
xloader.prototype.callreaday = function() {
    var args = arguments.callee.args;
    var loader = args.that.loader;
    if (typeof args[3] == "function" && loader.readyState == 4 && loader.status == 200) {
        args[3].apply(args.that, [loader.status, loader.responseXML, loader.responseText, args]);
    }
}